package com.kws.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.system.domain.SysUserMessage;
import com.kws.system.mapper.SysUserMessageMapper;
import com.kws.system.service.SysUserMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>SysUserMessageServiceImpl</b>
 *
 * @description: SysUserMessageServiceImpl <br>
 * @date: 2024/11/5 16:48 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class SysUserMessageServiceImpl extends ServiceImpl<SysUserMessageMapper, SysUserMessage> implements SysUserMessageService {
    private static final Logger logger = LoggerFactory.getLogger(SysUserMessageServiceImpl.class);


    @Override
    public void createMessageUser(List<Long> userIds, Long id,String type) {
        List<SysUserMessage> userMessagesList = new ArrayList<>();
        if ("update".equals(type)){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("message_id",id);
            baseMapper.delete(queryWrapper);
        }
        userIds.forEach(item -> {
            SysUserMessage sysUserMessage = new SysUserMessage();
            sysUserMessage.setUserId(item);
            sysUserMessage.setMessageId(id);
            userMessagesList.add(sysUserMessage);
        });
        this.saveBatch(userMessagesList);
    }
}
